<script setup>
import {version} from 'vue'
import {ElMessage as msg} from 'element-plus'
import axios from 'axios'

axios.defaults.baseURL = "http://localhost"

axios.defaults.timeout = 5000
axios.defaults.headers['token'] = 'littledesire'


// 请求拦截器
axios.interceptors.request.use(
    config=>{
      config.headers['token'] = 'T...............'
      return config
    },
    error => Promise.reject(error)
)




    function b1() {
      msg.success("hello vue")
    }

    function b2() {
      axios({
        url: '/api/show',
        method: 'get',
        params:{id:123,name:'刻晴'}
      }).then(res=>{
        console.log(res.data.data)
      }).then(err=>{
        console.log(err)
      })
    }

    function b3() {
    // 请求负载传值， 需要用@RequestBody来接值
      axios.post("/api/p",{id:111,name:'李四'}).then(res=>{
        console.log(res.data.msg)
      }).then(err=>{
        console.log(err)
      })
    }
    function b4() {
  // 表单传值
      axios({
        url: '/api/p2',
        method: 'post',
        params:{c:1},
        data:'id=123&name=asfasdfasdf',
        headers:{"Content-type": "application/x-www-form-urlencoded"}
      }).then(res=>{
        console.log(res.data)
      }).catch(err=>{
        console.log(err)
      })
    }
    function b5() {
      axios({
        url: '/api/p3',
        method: 'put',
        params:{c:1},
        data:'id=45&name=vfvx',
      }).then(res=>{
        console.log(res.data)
      }).catch(err=>{
        console.log(err)
      })
    }

    function b6() {
      axios.delete('/api/d?c=12345353',{
        params:{
          c:1,
          id: 4563456,
          name: '老实交代看回放'
        },
      }).then(res=>{
        console.log(res.data)
      }).catch(err=>{
        console.log(err)
      })
    }

    function b7() {
      axios({
          url:'/api/patch',
          method:'patch',
          id:546,
          data:{id:6,name:'铂金'},
          params:{c:123}
      }).then(res=>{
        console.log(res.data)
      }).catch(err=>{
        console.log(err)
      })
    }

</script>




<template>
  <h3>hello vue {{version}}</h3>
  <hr>
  <el-row>
    <el-button @click="b1">按钮</el-button>
    <el-button type="primary" @click="b2">axios -get</el-button>
    <el-button type="success" @click="b3">axios -post 请求负载传值</el-button>
    <el-button type="success" @click="b4">axios -post 表单传值</el-button>
    <el-button type="info" @click="b5">axios -put</el-button>
    <el-button type="info" @click="b6">axios -delete</el-button>
    <el-button type="danger" @click="b7">axios -patch</el-button>
  </el-row>
</template>

<style>

</style>
